#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include<QTcpSocket>
#include<QVector>
#include<QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
#include <QtCharts>
QT_CHARTS_USE_NAMESPACE


class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private slots:
    void on_USRP_clicked();
    void on_link_clicked();
    void on_CircleReq_clicked();
    void on_pushButton_clicked();
    void on_SingleReq_clicked();
    void on_cleanTableButton_clicked();
    void on_pauseButton_clicked();

    void updateTableData(double ber, double bler, double snr);
    void handleUDPData(const QByteArray& buf);
    void handleUSRPConnect(const QString& responseCode);

private:
    Ui::Widget *ui;
//    QTcpServer* server; //监听的套接字
//    QTcpSocket* conn;   //通信的套接字
    QTcpSocket* client;
    QTimer *myTimer;
    bool  checked;
    bool isPaused;
    bool  checked_circle;
    QString ip;
    QString port;
    QVector<double> mean_snr;
    QVector<double> vsnr;
    QVector<double> vtsnr;
    int send_times = 0;

    void addSecondSeries(QChart *chart, QLineSeries *&secondSeries, const QColor &lineColor) ;
    void initChart(QChartView *chartView, QLineSeries *&series, QChart *&chart, const QString &title, const QString &axisXTitle, const QString &axisYTitle, const QColor &lineColor) ;
    void setupChart(QChart *chart, const QString &title, const QString &axisXTitle, const QString &axisYTitle);
    static void setupAxis(QValueAxis *axis, const QString &title);
    void updateChart(QLineSeries *series, QChart *chart, const QVector<double> &data);
    void updateChart2(QLineSeries *series1, QLineSeries *series2, QChart *chart, const QVector<double> &data1, const QVector<double> &data2);

    QChartView *berChartView, *blerChartView, *snrChartView, *tsnrChartView;
    QLineSeries *berSeries, *blerSeries, *snrSeries, *tsnrSeries;
    QChart *berChart, *blerChart, *snrChart, *tsnrChart;
    QVector<double> vber, vbler;
    int dataCount = 0;

    QScatterSeries *xinzuoSeries = nullptr;
    QChart *xinzuoChart = nullptr;
    void updateData(const QJsonObject &circlereq_json);
    void setupAxisStyling(QValueAxis *axis);
    void updateImg(const QJsonObject &circlereq_json) ;


   /* float sum_ber;
    float sum_bler;
    float sum_snr;
    float sum_noise;
    float sum_signal;
*/

};
#endif // WIDGET_H
